package com.example.carrierapp.common;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.baidu.mobstat.StatService;
import com.example.carrierapp.config.ConstValue;
import com.example.carrierapp.dao.DaoMaster;
import com.example.carrierapp.dao.DaoSession;
import com.tencent.bugly.crashreport.CrashReport;

import org.greenrobot.greendao.database.Database;


public class CarrierApplication extends Application {
    public static Application mAppContext;
    private static DaoSession mDaoSession;

    @Override
    public void onCreate() {
        super.onCreate();
//        CrashHandler.getInstance().init(this);
//        Thread.setDefaultUncaughtExceptionHandler(CrashHandler.getInstance());
        mAppContext=this;
        //bugly
        CrashReport.initCrashReport(getApplicationContext(), "66d2ee2651", false);
        //百度统计
        StatService.start(this);
        initDao();
    }

    private void initDao()
    {
        DaoMaster.DevOpenHelper openHelper=new DaoMaster.DevOpenHelper(this, ConstValue.DB_NAME);
        Database db=openHelper.getWritableDb();
        DaoMaster daoMaster=new DaoMaster(db);
        mDaoSession = daoMaster.newSession();
    }

    public static DaoSession getDaoSession()
    {
        return mDaoSession;
    }

    public static Application getApplication()
    {
        return mAppContext;
    }

    public void exitApp() {
//        System.exit();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }
}
